package com.whisperarts.financer.app.model.rcp;

import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.whisperarts.financer.app.Application;
import com.whisperarts.financer.app.utils.Icons;
import com.whisperarts.financer.model.transaction.Category;

public class CategoriesLabelProvider extends StyledCellLabelProvider {
	/*
	@Override
	public String getText(Object element) {
		if (element instanceof AccountsCategory) {
			return ((AccountsCategory) element).getName();
		}
		return ((Account) element).getTitle();
	}
	
	@Override
	public Image getImage(Object element) {
		if (element instanceof AccountsCategory) {
			return PlatformUI.getWorkbench().getSharedImages()
				.getImage(ISharedImages.IMG_OBJ_FOLDER);
		}
		return PlatformUI.getWorkbench().getSharedImages()
			.getImage(ISharedImages.IMG_OBJ_FILE);
	}
	*/
	
	@Override
	public void update(ViewerCell cell) {
		Object element = cell.getElement();
		StyledString text = new StyledString();
		
		if (element instanceof Category) {
			Category category = (Category) element;
			text.append(category.getName());
			if (category.isIncome())
				cell.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(
						Application.PLUGIN_ID, Icons.INCOME).createImage());
			else 
				cell.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(
						Application.PLUGIN_ID, Icons.EXPENSE).createImage());
		}
		cell.setText(text.toString());
		cell.setStyleRanges(text.getStyleRanges());
		
		super.update(cell);
	}
}
